package com.qianfeng.xiaxk.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import java.util.HashMap;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.sina.weibo.SinaWeibo;

/**
 * Created by Administrator on 8/25/2015.
 * 用来判断用户是否登录的，登录信息
 */
public class LoginUtils {
    public static boolean isLogin(Context context){
        boolean isLogin=false;
        SharedPreferences sp = context.getSharedPreferences("login",Context.MODE_PRIVATE);
        isLogin = sp.getBoolean("islogin",false);
        Log.e("","----LoginUtils:"+isLogin);
        return isLogin;
    }
    public static void login(Context context,String nickName,String id,String icon,String vid,String state,String sex){
        SharedPreferences sp = context.getSharedPreferences("login",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("nickName",nickName);
        editor.putString("id",id);
        editor.putString("icon",icon);
        editor.putString("vid",vid);
        editor.putString("state",state);
        editor.putString("sex", sex);
        editor.putBoolean("islogin",true).commit();
    }

    /**
     * 得到当前登录用户的id
     * @return
     */
    public static HashMap<String,String> getLoginInfo(Context context){
        SharedPreferences sp = context.getSharedPreferences("login",Context.MODE_PRIVATE);
        HashMap<String,String>map = new HashMap<>();
        map.put("id", sp.getString("id",null));
        map.put("name", sp.getString("nickName",null));
        map.put("icon", sp.getString("icon",null));
        map.put("vid",sp.getString("vid",""));
        return map;
    }
    public static void loginout(Context context){
        SharedPreferences sp = context.getSharedPreferences("login",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("nickName","");
        editor.putString("id","");
        editor.putString("icon", "");
        editor.putBoolean("islogin",false).commit();


    }
}
